package collection;

import java.util.ArrayList;

public class TestGeneric {
    public static void main(String[] args) {
        //使用泛型类创建对象
        //注意:1泛型只能让使用引用类型 2.不停泛型对象不能相互赋值
        MyGeneric<String> myGeneric = new MyGeneric<String>();
        myGeneric.t = "hello";
        myGeneric.show("hello world");
        String s = myGeneric.getT();
        MyGeneric<Integer> myGeneric2 = new MyGeneric<Integer>();
        myGeneric2.t = 100;
        myGeneric2.show(200);
        Integer t = myGeneric2.getT();
        //泛型接口
        MyInterfaceImpl myInterface  =new MyInterfaceImpl();
        myInterface.server("张三");
        MyInterfaceImpl2 myInterfaceImpl2 = new MyInterfaceImpl2();
        System.out.println(myInterfaceImpl2.server(100));
        //泛型方法
        MyGenericMethod myGenericMethod = new MyGenericMethod();
        System.out.println(myGenericMethod.show("孙尚香"));
        System.out.println(myGenericMethod.show(250));
        System.out.println(myGenericMethod.show(3.14));
        ArrayList<Student> students = new ArrayList<>();
        System.out.println("======");
        students.add(new Student("zhangsan",32));
        students.add(new Student("lisi",45));
        for (int i = 0; i < students.size(); i++) {
            System.out.println(students.get(i));

    }

}
}
